home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SPAWNO41.ARJ / SPAWNPTH.ASM < prev    next >
Assembly Source File  |  1992-04-26  |  4KB  |  170 lines

  1.     NAME    spawnpth
  2.     TITLE    Path search for disk-swapping spawn() by Ralf Brown
  3.     PAGE    60,132
  4. ;-----------------------------------
  5. ; (c) Copyright 1990, 1991, 1992 Ralf Brown  All Rights Reserved
  6. ; This code may be redistributed as a part of the complete SPAWNO package,
  7. ; under its distribution conditions.
  8. ;-----------------------------------
  9. ;  SPAWNO v4.10
  10. ;
  11. ;  assembler defines:
  12. ;   __TINY__, __SMALL__, __COMPACT__, __MEDIUM__, __LARGE__, __HUGE__
  13. ;    exactly one of the above must be defined to specify the memory
  14. ;    model in use
  15. ;-----------------------------------
  16.  
  17. __BSS__ equ 1                ; yes, we are using uninitialized storage
  18.     INCLUDE RULES.ASI
  19.  
  20.     Header@                ; set up segment and group definitions
  21.  
  22. ; bit flags for the extensions which were found
  23. COM_EXT equ 1
  24. EXE_EXT equ 2
  25. USER_EXT equ 4
  26.  
  27. ;-----------------------------------------------------------
  28. ; initialized data
  29.  
  30. DSeg@
  31. IFNDEF __TP    ; defined in BSeg@ if __TP
  32. ExtSym@ _psp,WORD,__CDECL__
  33. ENDIF
  34.  
  35. PATH_EQUALS db 'PATH='
  36. PATH_EQUALS_LEN equ $-PATH_EQUALS
  37. DSegEnd@
  38.  
  39. ;-----------------------------------------------------------
  40. ; uninitialized data
  41.  
  42. BSeg@
  43. IFDEF __TP
  44. ExtSym@ _psp, WORD, __CDECL__
  45. ENDIF
  46.  
  47. env        dd ?
  48.  
  49. extrn ___SPAWN_PNAME:byte
  50. executable_path equ ___SPAWN_PNAME
  51. executable_pad    equ ___SPAWN_PNAME + 80
  52.  
  53. BSegEnd@
  54.  
  55. CSeg@
  56.     ASSUME    DS:DGROUP
  57.  
  58. extrn __SPAWN_ERRNO:near
  59. extrn __SPAWN_DDSEP:near
  60. extrn __SPAWN_CHECK_DIR:near
  61.  
  62. ;----------------------------------------------------------------
  63. ; char * pascal __spawn_search(const char *name) ;
  64. ;    given a program name, search the PATH for it, returning the full pathname
  65. ;    or NULL if not found
  66. ;----------------------------------------------------------------
  67. PubProc@ __SPAWN_SEARCH,__PASCAL__
  68. ; parameters
  69.  @name = DPTR_ [bp+2+cPtrSize]
  70. ; start of subroutine
  71.     ASSUME    DS:DGROUP,ES:NOTHING
  72.     push    bp
  73.     mov    bp,sp
  74. IFDEF __HUGE__
  75.     push    ds            ; save caller's DS
  76.     mov    ax,DGROUP        ;   and establish addressing to our
  77.     mov    ds,ax            ;   data segment
  78. ENDIF ;__HUGE__
  79.     push    es
  80.     push    di
  81.     push    si
  82. ; set up pointer to environment
  83. IFDEF __TINY__
  84.     mov    es,ds:[002Ch]
  85. ELSE
  86.     mov    es,_psp@
  87.     mov    es,es:[002Ch]
  88. ENDIF ;__TINY__
  89.     xor    di,di
  90.     jmp short find_path
  91. find_path_loop:
  92.     mov    al,0
  93.     cmp    byte ptr es:[di],al
  94.     je    found_path
  95.     cld
  96. find_path_loop2:
  97.     scasb                ; find terminating zero
  98.     jne    find_path_loop2
  99. find_path:
  100.     mov    cx,PATH_EQUALS_LEN
  101.     mov    si,offset DGROUP:PATH_EQUALS
  102.     repe    cmpsb
  103.     jne    find_path_loop
  104. found_path:
  105.     mov    word ptr env+2,es
  106.     mov    word ptr env,di
  107.     mov    byte ptr ___SPAWN_PNAME,0  ; start with null path
  108. search_loop:
  109. IF LDATA
  110.     push    word ptr @name+2
  111. ENDIF
  112.     push    word ptr @name
  113.     call    __SPAWN_CHECK_DIR
  114.     jnz    search_successful
  115.     or    al,al            ; was there a pathspec in the name?
  116.     jne    search_failed         ; don't look at PATH unless simple filename
  117.     les    bx,env
  118.     ASSUME    ES:NOTHING
  119.     cmp    byte ptr es:[bx],0
  120.     je    search_failed
  121.     mov    di,offset DGROUP:executable_path
  122. dir_copy_loop:
  123.     mov    al,es:[bx]
  124.     or    al,al
  125.     je    dir_copy_done
  126.     inc    bx
  127.     cmp    al,';'            ; separator for path entries
  128.     je    dir_copy_done
  129.     mov    [di],al
  130.     inc    di
  131.     cmp    di,offset DGROUP:executable_pad      ; make sure we don't overrun buf
  132.     jb    dir_copy_loop
  133. dir_copy_done:
  134.     mov    al,[di-1]
  135.     call    __spawn_ddsep        ; was last char a slash/backslash/colon?
  136.     je    dir_has_slash
  137.     mov    byte ptr [di],'\'
  138.     inc    di
  139. dir_has_slash:
  140.     mov    byte ptr [di],0
  141.     mov    word ptr env,bx
  142.     jmp    search_loop
  143.  
  144. search_successful:
  145.     mov    ax,bx
  146. IF LDATA
  147.     mov    dx,ds
  148. ENDIF
  149.     jmp short search_done
  150. search_failed:
  151.     mov    ax,2            ; file not found
  152.     call    __SPAWN_ERRNO
  153.     xor    ax,ax
  154. IF LDATA
  155.     xor    dx,dx
  156. ENDIF
  157. search_done:
  158.     pop    si
  159.     pop    di
  160.     pop    es
  161. IFDEF __HUGE__
  162.     pop    ds
  163. ENDIF ;__HUGE__
  164.     pop    bp
  165.     ret    dPtrSize
  166. EndProc@ __SPAWN_SEARCH,__PASCAL__
  167.  
  168. CSegEnd@
  169.     END
  170.